package com.stress.testing.plugin.open.feign;

import com.stress.testing.common.matcher.ClassDescription;
import com.stress.testing.common.matcher.ClassMatcher;
import com.stress.testing.common.matcher.MethodDescription;
import com.stress.testing.common.matcher.MethodMatcher;
import com.stress.testing.common.plugin.AbstractPlugin;

import java.util.Collections;
import java.util.List;

public class SynchronousMethodHandlerPlugin extends AbstractPlugin {
    @Override
    public ClassMatcher getClassMatcher() {
        return new ClassMatcher() {
            @Override
            public boolean match(ClassDescription classDescription) {
                return "feign.SynchronousMethodHandler".equals(classDescription.getName());
            }

            @Override
            public List<MethodMatcher> getMethodMatchers() {
                return Collections.singletonList(new MethodMatcher() {
                    @Override
                    public boolean match(MethodDescription methodDescription) {
                        return "targetRequest".equals(methodDescription.getName());
                    }

                    @Override
                    public String getInterceptor() {
                        return "com.stress.testing.plugin.open.feign.interceptor.SynchronousMethodHandlerTargetRequestInterceptor";
                    }
                });
            }
        };
    }
}
